PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Specifying a File by Name or Pathname

To be sure that a command acts on the correct file, specify the entire pathname, including the names of the volume and the entire sequence of folders that you would have to open to find the file.

If you use a reference of the form file nameString , AppleScript doesn't attempt to locate the file until the script is actually run. When AppleScript executes the statement that accesses the file, the file must exist in the specified folder (or, if only a filename was provided, in the current directory) for AppleScript to locate it. Some commands, such as the Save command, create a file with the specified name in the specified location if it doesn't already exist. Some commands, such as the Close and Save commands, may replace an existing file with the same name as the specified file (if one exists).

tell application "Finder"
    open file "Hard Disk:June Sales"
end tell

A disadvantage of specifying a file by name or pathname is that if the user moves the file or renames the file or a folder in its pathname, AppleScript won't be able to find the file and the script will not complete correctly. For a more robust approach, see Specifying a File by Alias.

For a sample script that shows how a script application can handle pathnames of files dropped on it, see Open Handlers.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)